<template>
  <div style="width:100%;height:100%">
<div v-if="$router.history.current.query.data==1" style="width:100%;height:100%">
    <div class="smallbox">
        <van-button type="info"  @click="selectAll1()">全选</van-button>
        <van-button type="info"  @click="noselectAll1()">取消</van-button>
   <van-search
  v-model="value1"
  show-action
  placeholder="请输入搜索关键词"
  @search="onSearch1"
>
  <template #action>
    <div @click="onSearch1">确认</div>
  </template>
</van-search>

    </div>
    <div class="center">
        <div class="box" v-for="(item,i) in list1" :key="i" >
    <van-checkbox v-model="item.checked" shape="square">{{item.BUKRST}}</van-checkbox>

    <van-divider />
</div>
    </div>
<div class="bot">
     <!-- <van-button type="info"  size="large"  @click="handlReturn">全部取消</van-button> -->
    <van-button type="info"  size="large" @click="handlReturn">返回</van-button>
</div>
</div>


<div v-else style="width:100%;height:100%"> 
    <div class="smallbox">
        <van-button type="info"  @click="selectAll2()" >全选</van-button>
        <van-button type="info"  @click="noselectAll2()">取消</van-button>
   <van-search
  v-model="value2"
  show-action
  placeholder="请输入搜索关键词"
  @search="onSearch2"
>
  <template #action>
    <div @click="onSearch2">确认</div>
  </template>
</van-search>
    </div>
    <div class="center">
        <div class="box" v-for="(item,i) in result1" :key="i" >
    <van-checkbox v-model="item.checked" shape="square" >{{item.KOSTLT}}</van-checkbox>

    <van-divider />
    
</div>
    </div>
<div class="bot">
    <!-- <van-button type="info"  size="large"  @click="handlReturn">全部取消</van-button> -->
    <van-button type="info"  size="large"  @click="handlReturn">返回</van-button>
</div>
</div>



  </div>
</template>

<script>
import awsuiAxios from "../awsuiAxios";
export default {
data(){
    return {
        sms:'',
        value1:'',
        value2:'',
        list: [],
        list1: [],
        result:[],
        result1:[]
    }
},
watch:{
    value1( newVla, oldVal){
      this.list1 = this.list.filter(item=>{
        return item.BUKRST.includes(newVla)
      })
    },
    value2( newVla, oldVal){
      this.result1 = this.result.filter(item=>{
        return item.KOSTLT.includes(newVla)
      })
    }
},

mounted(){
    // this.list = this.$router.history.current.query.data
     this.list = this.$store.state.Company 
     this.list1 = this.list
    console.log(333,this.list);
    this.result = this.$store.state.Center 
    this.result1 = this.result
   
    // this.result = this.$router.history.current.query.data2
},
methods: {
    handlReturn(){
        this.$router.back()
    },
    onSearch1(){
        console.log(123123,this.list);
        console.log(JSON.stringify(this.list)!=JSON.stringify(this.$store.state.Company));
        
            this.getCenter()
        
        this.$store.state.Company = this.list
        this.$router.push({path:'/CreateSheet',query:{data:this.list}})
    },
    onSearch2(){
        this.$store.state.Center = this.result
        this.$router.push({path:'/CreateSheet',query:{data:this.list}})
    },
    selectAll1(){
        console.log(this.list);
        this.list1.forEach(item=>{
            item.checked = true
        })
        
    },
    noselectAll1(){
        console.log(this.list);
        this.list1.forEach(item=>{
            item.checked = false
        })
        
    },
    selectAll2(){
        console.log(this.list);
        this.result1.forEach(item=>{
            item.checked = true
        })
    },
    noselectAll2(){
        console.log(this.list);
        this.result1.forEach(item=>{
            item.checked = false
        })
    },
    getCenter(){
    const that = this
    // this.inventoryCompany = JSON.parse(this.inventoryCompany)
    // console.log("123",this.inventoryCompany);
    let temp = ''
              this.$store.state.Company.forEach(item => {
               if(item.checked===true){
                if(temp==''){
                 temp +=item.BUKRS
               }else{
                 temp +=","+item.BUKRS
               }
               }
              });
    awsuiAxios.post({
              url: 'jd',
                data: {
                    cmd: "com.awspaas.user.apps.assetinventory_selectCostCenter",
                    sid:sid,
                    companys:temp
                }
            }).then(function (ro) {
                if (ro.result == 'ok') {
                    // that.message = ro.data.staffList
                    // that.$router.push({path:'/show',query:{data:ro.data.staffList}})
                   ro.data.costCenter.forEach(element => {
                    that.$set(element,"checked",false)
                   });
                    that.$store.state.Center  = ro.data.costCenter
                    
                }else{
                        Toast.fail('' + ro.msg);
                      }
            }).catch(error => {
                console.log(error);
            })
  },
  },
}
</script>

<style scoped>
::v-deep .van-checkbox__label{
    font-size: 12px;
}
.center{
    height:84%;
    overflow-y: scroll;
    margin-bottom: 10px;
}
.box {
    padding: 0px 4px;
    height: 30px;
    display: flex;
    align-content: center;
}
.smallbox{
    display: flex;
    justify-content: space-between;
    align-items: center;
}
::v-deep .van-button--normal {
    padding: 0 2px 0 2px;
    height: 33px;
    margin-left:4px ;
}
::v-deep .van-search{
    flex: 1;
    padding: 10px 3px;
}
.bot{
    display: flex;
    width: 100%;
    /* height: 10%; */
    position:fixed;
    bottom: 0;
}
</style>